The Enterprise JavaBean (EJB) specification from Sun Microsystems, Inc. of Palo Alto, Calif., defines a way to do multi-platform transaction processing in Java. The EJB spec utilizes containers in which transaction-oriented applications can be written. The EJB architecture includes several elements, including session beans that control work flow and client interaction, as well as entity beans that interact with external resources such as databases and other enterprise servers. Entity beans can represent data elements, such as database elements that are represented to an application.
Access is gained to an EJB through a Home interface, using an EJB server and relevant EJB container. The EJB container provides access to an entity bean under “managed persistence,” whereby the entity bean does not need to be loaded into memory. The loading is done by the container through Container Managed Persistence (CMP), or by the entity bean itself using Bean Managed Persistence (BMP). Each entity bean can provide at least one finder method, which provides a user with a way to look up the bean when needed.
The EJB specification describes ways to execute queries against a database, as well as ways for a user to communicate queries to an EJB container. A user develops a query before deploying an EJB. Once the EJB is deployed, the user can execute the query. When executing a query, the component executing the query will iterate through all the results of the query. These results will then be used to populate other EJBs. All these EJBs are then handed back to the user in one big collection. This can waste system resources unnecessarily, as a user may only be interested in certain results and does not need to be sent the entire result set.